package com.wyzz.hr.action;

import java.util.*;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.wyzz.hr.base.BaseDownloadAction;
import com.wyzz.hr.bo.IEmpSalaryAcctitemsBo;
import com.wyzz.hr.bo.IEmpSalaryAcctversionBo;
import com.wyzz.hr.pojo.Empsalaryacct;
import com.wyzz.hr.pojo.Empsalaryacctversion;
import com.wyzz.hr.util.BaseCrit;
import com.wyzz.hr.util.Pager;

public class SearchEmpsalaryacct extends BaseDownloadAction {

	public SearchEmpsalaryacct() {
		page = new Pager();
		searchOrExport = null;
	}

	public String execute() throws Exception {
		empsalaryacctversionList = searchEmpAcctVer();
		IEmpSalaryAcctitemsBo esaiBo = (IEmpSalaryAcctitemsBo) getBean("empsalaryacctitemsBo");
		if ("export".equals(searchOrExport)) {
			List esavIds = new ArrayList();
			Empsalaryacctversion version;
			for (Iterator i$ = empsalaryacctversionList.iterator(); i$
					.hasNext(); esavIds.add(version.getId()))
				version = (Empsalaryacctversion) i$.next();

			List allItemsList = esaiBo.getAllItemsByEsavIds(esavIds);
			getClass();
			return downloadToExcel(allItemsList, "OSalaryAcctAll",
					outmatchModelId);
		} else {
			return "success";
		}
	}

	private List searchEmpAcctVer() {
		DetachedCriteria dc = DetachedCriteria
				.forClass(Empsalaryacctversion.class);
		dc.createAlias(Empsalaryacctversion.PROP_ESAV_ESAC, "esavEsac", 1);
		addOrders(dc, page, new String[] {
				(new StringBuilder()).append("esavEsac.").append(
						Empsalaryacct.PROP_ESAC_NAME).append("-up").toString(),
				(new StringBuilder()).append(
						Empsalaryacctversion.PROP_ESAV_VALID_FROM).append(
						"-down").toString() });
		BaseCrit.addDC(dc, (new StringBuilder()).append("esavEsac.").append(
				Empsalaryacct.PROP_ESAC_NAME).toString(), "like",
				new String[] { esacName });
		if (versionFlag == null)
			dc.add(Restrictions.isNull("esavValidTo"));
		IEmpSalaryAcctversionBo esavBo = (IEmpSalaryAcctversionBo) getBean("empsalaryacctversionBo");
		return esavBo.findEsav(dc, page, searchOrExport);
	}

	public String getEsacName() {
		return esacName;
	}

	public void setEsacName(String esacName) {
		this.esacName = esacName;
	}

	public List getEmpsalaryacctversionList() {
		return empsalaryacctversionList;
	}

	public void setEmpsalaryacctversionList(List empsalaryacctversionList) {
		this.empsalaryacctversionList = empsalaryacctversionList;
	}

	public Pager getPage() {
		return page;
	}

	public void setPage(Pager page) {
		this.page = page;
	}

	public String getVersionFlag() {
		return versionFlag;
	}

	public void setVersionFlag(String versionFlag) {
		this.versionFlag = versionFlag;
	}

	public String getOutmatchModelId() {
		return outmatchModelId;
	}

	public void setOutmatchModelId(String outmatchModelId) {
		this.outmatchModelId = outmatchModelId;
	}

	public String getSearchOrExport() {
		return searchOrExport;
	}

	public void setSearchOrExport(String searchOrExport) {
		this.searchOrExport = searchOrExport;
	}

	private static final long serialVersionUID = 1L;
	private Pager page;
	private String esacName;
	private String versionFlag;
	private List empsalaryacctversionList;
	private String searchOrExport;
	private String outmatchModelId;
	public final String outputIoName = "OSalaryAcctAll";
}
